﻿/*1942 game clone
 * Authors:
 * Abdollah Tabareh
 * Bharat Bhushan Konka
 * Martin Svensson 
 * Richard Zianne
 * Tigran Harutyunyan
 * 
 * 2010
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Game1942
{
    class ScoreManager
    {
        public static int[] readScore()
        {
            try
            {
                TextWriter createFile = new StreamWriter("scores.dat",true);
                createFile.Close();
            }
            catch(Exception e)
            {
            }
            String line = "";
            TextReader tr = new StreamReader("scores.dat");
            line = tr.ReadToEnd();
            tr.Close();
            String[] scoresTxt = line.Split('#');
            int[] scores = new int[scoresTxt.Length];
            String next;
            for (int i = 0; i < scoresTxt.Length; i++)
            {
                next = scoresTxt[i];
                if (next == "")
                {
                    scores[i] = 0;
                    continue;
                }
                scores[i] = Convert.ToInt32(next);
            }

            Array.Sort(scores);
            Array.Reverse(scores);
            return scores;
        }

        public static void saveScore(int newScore)
        {
            String line = "";

            TextWriter tw = new StreamWriter("scores.dat",true);            
            line += newScore;
            line += "#";
            tw.Write(line);
            tw.Close();
        }
    }
}
